package sg.edu.nus.iss.vmcs.customer;

import java.awt.Button;
import java.awt.event.*;

import sg.edu.nus.iss.vmcs.util.VMCSException;

/**
 * 
 * @version 1.1
 * @author Qu Hui
 *
 */
public class CoinInputListener implements ActionListener {

	private CoinReceiver coinReceiver;

	public CoinInputListener(CoinReceiver coinReceiver) {
		this.coinReceiver = coinReceiver;
	}

	public void actionPerformed(ActionEvent e) {
		Button btn;
		String cmd;
		int idx;

		btn = (Button) e.getSource();
		cmd = btn.getActionCommand();
		idx = Integer.parseInt(cmd);

		int weight = coinReceiver.getTransactionController().getCustomerPanel()
				.getCoinInputBox().getCoinWeight(idx);

		// coinReceiver.receiveCoin(weight);
		String cmdStr = "ReceiveCoin";
		TransactionController disp = coinReceiver.getTransactionController();
		try {
			disp.dispatch(cmdStr, weight);
		} catch (VMCSException e1) {
			System.out.println(e1.getMessage());
		}
	}
}
